package com.infore.dataStatistics.main.cal.chain;

import com.infore.common.base.Msg;
import com.infore.dataStatistics.main.cal.Calculator;
import com.infore.dataStatistics.main.cal.impl.WqlCal;
import com.infore.dataStatistics.main.dto.StatTask;

import java.util.ArrayList;
import java.util.List;

public class ChainOfResponsibilityClient {

    private List<Calculator> cals;

    public ChainOfResponsibilityClient() {
        cals = new ArrayList<Calculator>();
    }

    public void addCal(Calculator cal){
        cals.add(cal);
    }

    public Msg<Object> execute(StatTask task){
        List<Calculator> calList = new ArrayList<>();
        calList.addAll(cals);

        //将新加入的客户端加入集合中
        calList.add(new WqlCal());

        RealChain realChain = new RealChain(task, calList, 0);
        return realChain.proceed(task);
    }

}
